<?php
// ALTSYS Check
if (! file_exists(XOOPS_TRUST_PATH .'/libs/altsys/class/D3LanguageManager.class.php')) {
	die('install the latest altsys');
}

require_once dirname(__FILE__) . '/class/links_router.class.php';

if ($Router = new LINKS_Router($mydirname)) {

	require_once dirname(__FILE__) . '/class/links_Base.class.php';

	$class_file = $Router->fetch_class();
	$method     = $Router->fetch_method();
//var_dump($class_file);var_dump($method);var_dump($Router->fetch_args());

	// File Load
	$class_file_path = dirname(__FILE__) .'/main/'. $class_file .'.php';
	if (!file_exists($class_file_path)) {
		redirect_header(XOOPS_URL . '/', 2, 'No File');//TODO
		exit();
	}
	require_once $class_file_path;

	// Instance
	$class_name = 'links_'. $class_file;
	if (! class_exists($class_name) || strncmp($method, '_', 1) == 0 || ! in_array($method, get_class_methods($class_name))) {
		redirect_header(XOOPS_URL . '/', 2, 'No Method');//TODO
		exit();
	}
	$Links_controller = new $class_name($mydirname);

	// Delegate
	if (defined('XOOPS_CUBE_LEGACY')) {
		$pm = $Links_controller->Links->is_mobile ? 'Mobile': 'Pc';
		$delegate_name = ucfirst(strtolower($mydirname)) .'.'. ucfirst(strtolower($class_file)) .'.'. ucfirst(strtolower($method)) .'.'. $pm;
		$Links_controller->delegate_name = $delegate_name;
		XCube_DelegateUtils::call($delegate_name .'.'. 'BeforeExec', new XCube_Ref($Links_controller));
	}

	// Execute Method
	call_user_func_array(array(&$Links_controller, $method), $Router->fetch_args());

} else {
	redirect_header(XOOPS_URL . '/', 2, 'No Execute');//TODO
	exit();
}
